﻿using System.Collections.Generic;
using Catel.Articles._03___MVVM.Models;

namespace Catel.Articles._03___MVVM
{
    /// <summary>
    /// 
    /// </summary>
    internal static class DataHelper
    {
        #region Variables
        private static readonly List<Person> _randomEmployees = new List<Person>();
        #endregion

        #region Constructor & destructor
        /// <summary>
        /// Initializes the <see cref="DataHelper"/> class.
        /// </summary>
        static DataHelper()
        {
            // Create random employees (generated with "The Random Name Generator" at http://www.kleimo.com/random/name.cfm)
            _randomEmployees = new List<Person>();
            _randomEmployees.Add(CreatePerson("John", "", "Doe", Gender.Male));
            _randomEmployees.Add(CreatePerson("Pettey", "", "Clayton", Gender.Male));
            _randomEmployees.Add(CreatePerson("Lonnie", "", "Hodel", Gender.Male));
            _randomEmployees.Add(CreatePerson("Cody", "", "Monroig", Gender.Male));
            _randomEmployees.Add(CreatePerson("Wotton", "", "Tyrone", Gender.Male));
            _randomEmployees.Add(CreatePerson("Jessie", "", "Blahnik", Gender.Male));
        }
        #endregion

        #region Methods
        /// <summary>
        /// Creates a company.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="numberOfEmployees">The number of employees.</param>
        /// <returns></returns>
        public static Company CreateCompany(string name, int numberOfEmployees)
        {
            // Create company
            Company company = new Company();
            company.Name = name;
            
            // Create CEO
            Person ceo = CreatePerson("Geert", "van", "Horrik", Gender.Male);

            // Create number of employees
            for (int i = 0; i < numberOfEmployees; i++)
            {
                if (i >= _randomEmployees.Count) break;

                ceo.PersonCollection.Add(CreatePerson(_randomEmployees[i]));
            }

            // Set CEO
            company.CEO = ceo;

            // Return company
            return company;
        }

        /// <summary>
        /// Creates a person.
        /// </summary>
        /// <param name="firstName">The first name.</param>
        /// <param name="middleName">Name of the middle.</param>
        /// <param name="lastName">The last name.</param>
        /// <param name="gender">The gender.</param>
        /// <returns></returns>
        public static Person CreatePerson(string firstName, string middleName, string lastName, Gender gender)
        {
            // Create person
            Person person = new Person();
            person.FirstName = firstName;
            person.MiddleName = middleName;
            person.LastName = lastName;
            person.Gender = gender;

            // Return it
            return person;
        }

        /// <summary>
        /// Creates the person.
        /// </summary>
        /// <param name="existingPerson">The existing person.</param>
        /// <returns></returns>
        private static Person CreatePerson(Person existingPerson)
        {
            // Create person
            Person person = new Person();
            person.FirstName = existingPerson.FirstName;
            person.MiddleName = existingPerson.MiddleName;
            person.LastName = existingPerson.LastName;
            person.Gender = existingPerson.Gender;

            // Return it
            return person;
        }
        #endregion
    }
}
